package com.fxp.project.jiuselu.web.business.v1.controller.sample;

import com.fxp.project.jiuselu.commons.utils.RandomUtils;
import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.business.v1.request.order.ReqOrderCart;
import com.fxp.project.jiuselu.web.domain.CommonResult;
import com.fxp.project.jiuselu.web.models.sample.entity.SampleOrder;
import com.fxp.project.jiuselu.web.models.sample.entity.vo.SampleOrderVo;
import com.fxp.project.jiuselu.web.models.sample.service.ISampleOrderService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 样品订单Controller
 *
 * @author Jason.Wang
 * @date 2022-06-08
 */
@RestController
@RequestMapping("/sample/order")
public class SampleOrderController extends BaseController
{
    @Autowired
    private ISampleOrderService sampleOrderService;


    /**
     * 查询用户样品订单列表
     */
    @PostMapping("/list")
    @CrossOrigin
    public CommonResult list(SampleOrder sampleOrder)
    {
        PageInfo<?> pageInfo = sampleOrderService.selectSampleOrderList(sampleOrder);
//        List<SampleOrder> list = sampleOrderService.selectSampleOrderList(sampleOrder);
        return CommonResult.success(pageInfo);
    }


    /**
     * 样品订单列表
     *
     * @param userId 登陆者用户id
     * @return
     */
    @PostMapping("/sample/total/{userId}/{orderTotalStatus}")
    @CrossOrigin
    public CommonResult getSampleOrder(@PathVariable("userId") Long userId, @PathVariable("orderTotalStatus") Integer orderTotalStatus) {
        List<SampleOrderVo> maps = sampleOrderService.selectSampleListByUserIdStatus(userId, orderTotalStatus);
        return CommonResult.success(maps);
    }


    /**
     * 新增样品订单
     */
    @PostMapping
    @CrossOrigin
    public CommonResult add(@RequestBody @Validated ReqOrderCart reqOrderCart,Long userId)
    {
        return CommonResult.success(sampleOrderService.insertSampleOrder(reqOrderCart,userId));
    }

    /**
     * 获取样品订单详细信息
     */
    @PostMapping("/getInfo/{sampleId}")
    @CrossOrigin
    public CommonResult getInfo(@PathVariable("sampleId") String sampleId)
    {
        return CommonResult.success(sampleOrderService.selectSampleOrderBySampleId(sampleId));
    }

    /**
     * 删除样品订单
     */
    @PostMapping("/{sampleIds}")
    @CrossOrigin
    public CommonResult remove(@PathVariable String[] sampleIds)
    {
        return CommonResult.success(sampleOrderService.deleteSampleOrderBySampleIds(sampleIds));
    }

    /**
     * 修改样品订单
     */
    @PostMapping("/edit")
    @CrossOrigin
    public CommonResult edit(@RequestBody SampleOrder sampleOrder)
    {
        return CommonResult.success(sampleOrderService.updateSampleOrder(sampleOrder));
    }

}


